package net.anzhuo.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsEmployeesMapper;
import net.anzhuo.entity.GsEmployees;
import net.anzhuo.service.GsEmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class GsEmployeesServiceImpl implements GsEmployeesService {

	@Autowired
	private GsEmployeesMapper gsEmployeesMapper;

	@Override
	public PaginationVO<GsEmployees> getListWithPage(GsEmployees gsEmployees) {
		PaginationVO<GsEmployees> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsEmployeesMapper.getListWithPage(gsEmployees));
		paginationVO.setTotalCount(gsEmployeesMapper.getCount(gsEmployees));
		paginationVO.setTotalPage((gsEmployeesMapper.getCount(gsEmployees) + gsEmployees.getPageSize() -1)  / gsEmployees.getPageSize());
		paginationVO.setPageNo(gsEmployees.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsEmployees> getByMd5(String md5) {
		return gsEmployeesMapper.getByMd5(md5);
	}

	@Override
	public GsEmployees getById(Long id) {
		return gsEmployeesMapper.getById(id);
	}

	@Override
	public List<GsEmployees> getList() {
		return gsEmployeesMapper.getList();
	}

	@Override
	public List<GsEmployees> getList(GsEmployees gsEmployees) {
		return gsEmployeesMapper.getListByQuery(gsEmployees);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsEmployees gsEmployees) {
		gsEmployeesMapper.update(gsEmployees);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsEmployees gsEmployees) {
		gsEmployeesMapper.save(gsEmployees);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(GsEmployees gsEmployees) {
		gsEmployeesMapper.delete(gsEmployees);
	}
}
